<?php

// +----------------------------------------------------------------------
// | TAODUDU.COM  [ Simple Efficient Excellent ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://www.taodudu.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: ubten <462193409@qq.com> http://www.ubten.com/
// +----------------------------------------------------------------------

namespace Admin\Controller;
use Admin\Controller\AdminController;
class MsgtplController extends AdminController {
    
    function _initialize() {
        parent::_initialize();
        $this->assign('sys', 'setting'); // 数据集
    }
    //手机消息模板
    //
    public function index(){
        $users = M('msgTpl');
        $count = $users->count();// 查询满足要求的总记录数
        $Page = new \Think\Page($count,15);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show = $Page->show();// 分页显示输出
        $list = $users->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
        $this->assign('list',$list);// 赋值数据集
        $this->assign('pages',$show);// 赋值分页输出
        $this->assign('action', 'msgtpl');
        $this->display();
    }
    
    public function add(){
        if(IS_POST){
            $data['title'] = I('title');
            $data['is_mobile'] = I('is_mobile');
            $data['is_email'] = I('is_email');
            $data['email'] = cJscript($_POST['email']);
            $data['mobile'] = I('mobile');
            $data['created'] = NOW_TIME;
            $re = M('msgTpl')->add($data);
            if($re){
                $this->success('模版添加成功！',U('index'));
            }else{
                $this->error('模版添加失败！');
            }
        }
        $this->assign('action', 'msgtpl');
        $this->display();
    }
    
    
    public function edit(){
        $id = I('id');
        $map['id'] = $id;
        if(IS_POST){
            $data['title'] = I('title');
            $data['is_mobile'] = I('is_mobile');
            $data['is_email'] = I('is_email');
            $data['email'] = cJscript($_POST['email']);
            $data['mobile'] = I('mobile');
            $data['created'] = NOW_TIME;
            $re = M('msgTpl')->where($map)->save($data);
            if($re){
                $this->success('模版修改成功！',U('index'));
            }else{
                $this->error('模版修改失败！');
            }
        }
        
        $config = M('msgTpl')->where($map)->find();
        $this->assign('config',$config);
        $this->assign('action', 'msgtpl');
        $this->display();
    }
    
    public function del(){
        $Id = I('post.data', 0, 'intval');
        if (empty($Id)) {
            $this->error('参数不能为空！');
        }
        if (M('msgTpl')->where('id=' . $Id)->delete()) {
            $this->success('删除成功！', U('my'));
        } else {
            $this->error('删除失败！');
        }
    }
    
    //put your code here
}
